package com.zh.yqbj.schedule;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zh.yqbj.entity.UserSpace;
import com.zh.yqbj.service.SpaceService;
import com.zh.yqbj.service.UserSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class CalcSpaceSizeTask {
    @Autowired
    UserSpaceService userSpaceService;
    @Autowired
    SpaceService spaceService;

//    @Scheduled(cron = "0 */1 * ? * *") // 每一分钟执行一次
//    public void calcSpaceSize() {
//        System.out.println("每一分钟更新一次");
//
//
//    }

    // 早上八点执行
    @Scheduled(cron = "0 0 8 * * *")
    public void morningTask() {
        // 执行早上任务逻辑
        System.out.println("早上八点执行任务...");
        List<String> spaceIds =
                userSpaceService.list().stream().map(UserSpace::getSpaceId).collect(Collectors.toList());
        spaceService.calcAllSpaceSize(spaceIds);
    }

    // 下午十六点执行
    @Scheduled(cron = "0 0 16 * * *")
    public void afternoonTask() {
        // 执行下午任务逻辑
        System.out.println("下午十六点执行任务...");
        List<String> spaceIds =
                userSpaceService.list().stream().map(UserSpace::getSpaceId).collect(Collectors.toList());
        spaceService.calcAllSpaceSize(spaceIds);
    }

    // 晚上二十四点（即午夜）执行
    @Scheduled(cron = "0 0 0 * * *")
    public void midnightTask() {
        // 执行夜间任务逻辑
        System.out.println("晚上二十四点执行任务...");
        List<String> spaceIds =
                userSpaceService.list().stream().map(UserSpace::getSpaceId).collect(Collectors.toList());
        spaceService.calcAllSpaceSize(spaceIds);
    }
}
